package com.zxy.controller;

import com.zxy.config.annotation.Doc;
import com.zxy.config.annotation.NoAuthorization;
import com.zxy.domain.WebUrl;
import com.zxy.service.WebUrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/web-url")
public class WebUrlController {


    @Autowired
    private WebUrlService webUrlService;

    /**
     * 查询所有的web-url
     */
    @RequestMapping(value = "/all",method = RequestMethod.GET)
    @NoAuthorization
    @Doc(doc = "查询项目中所有接口")
    public Map<String, List<WebUrl>> findAllWebUrl(){
        HashMap<String, List<WebUrl>> map = new HashMap<>();
        List<WebUrl> allWebUrl = webUrlService.findAllWebUrl();
        map.put("urls",allWebUrl);
        return map;
    }

    /**
     * 更新url激活状态
     */
    @RequestMapping(value = "/update",method = RequestMethod.GET)
    @NoAuthorization
    @Doc(doc = "更新项目接口是否开启和关闭")
    public Map<String,Object> updateWebUrl(String webUrl,Boolean enable){
        HashMap<String, Object> map = new HashMap<>();
        int i = webUrlService.updateWebUrlEnable(webUrl, enable);
        if (i>0){
            map.put("status","200");
            map.put("msg","更新成功");
        }else {
            map.put("status","500");
            map.put("msg","更新失败");
        }
        return map;
    }
}
